/** 
 * <pre>项目名称:ssm-user-wdd 
 * 文件名称:SendCode.java 
 * 包名:com.jk.wdd.utils 
 * 创建日期:2022年7月6日上午11:27:53 
 * Copyright (c) 2022, yuxy123@gmail.com All Rights Reserved.</pre> 
 */  
package com.jk.utils;

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSONObject;

public class SendCode {

	// 手机号短信登入 发送短信  网易云信 
		public static JSONObject sendCode(String phone) {
			//请求路径
			String url = "https://api.netease.im/sms/sendcode.action";
			//head参数
			HashMap<String, Object> headParams = new HashMap<String, Object>();
			//App key
			headParams.put("AppKey", "54dd6ef0a7353627417ee7678a281954");
			
			//6位随机数
	
			String round = Math.round(Math.random()*899999+100000)+"";
			headParams.put("Nonce", round);
			//时间戳
			String time = System.currentTimeMillis()+"";
			headParams.put("CurTime", time);
			//SHA1(AppSecret + Nonce + CurTime)，将该三个参数拼接的字符串进行 SHA1 哈希计算从而生成 16 进制字符（类型为 String，小写）
																	//换 密钥        
			headParams.put("CheckSum", CheckSumBuilder.getCheckSum("d1593f8649cb", round, time));
			
			
			//body参数
			HashMap<String, Object> params = new HashMap<String, Object>();
			//手机号
			params.put("mobile", phone);
			//模板编号
			params.put("templateid", "19516280");
			//验证码
			params.put("authCode", round);
			
			System.out.println("验证码："+round);
			String str = HttpClientUtil.post2(url, params, headParams);
			System.out.println(str);
			 JSONObject obj = JSONObject.parseObject(str);
			return obj;
		}
	
}
